Skip to content

fix: indexer getting stuck when syncing from genesis - #3647

Merged
gilcu3 merged 3 commits into
mainfrom
3623-mpc-indexer-wedges-at-genesis-on-a-freshly-state-synced-node
Jun 24, 2026
Merged

fix: indexer getting stuck when syncing from genesis#3647
gilcu3 merged 3 commits into
mainfrom
3623-mpc-indexer-wedges-at-genesis-on-a-freshly-state-synced-node

Conversation

@gilcu3

@gilcu3 gilcu3 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Closes #3623

@gilcu3 gilcu3 linked an issue Jun 23, 2026 that may be closed by this pull request
@gilcu3
gilcu3 force-pushed the 3623-mpc-indexer-wedges-at-genesis-on-a-freshly-state-synced-node branch from 3c5addf to d9f6205 Compare June 23, 2026 07:37
@gilcu3
gilcu3 marked this pull request as ready for review June 23, 2026 07:44
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown

Pull request overview

Fixes #3623, where the MPC indexer wedges at genesis on a fresh state-synced node. The root cause was creating the block streamer (indexer.streamer()) before neard had finished syncing — at that point neard is still at genesis, so the streamer's LatestSynced cursor was pinned to genesis, below the node's block tail. The fix defers stream creation until wait_for_full_sync() resolves, and extracts the wait + listen sequence into a new stream_blocks_after_sync helper that races against shutdown_token.

Changes:

  • New stream_blocks_after_sync helper that lazily creates the stream only after sync completes, racing the whole sequence against shutdown.
  • Replaces the two cfg-duplicated select! blocks with a single call into the helper, using #[cfg(...)] on the conditional process_blocks_receiver argument to listen_blocks.
  • Adds three unit tests covering: stream-started-after-sync, no-stream-when-shutdown-precedes-sync, and listen-error-propagation.

Reviewed changes

Per-file summary
File Description
crates/node/src/indexer/real.rs Defers indexer.streamer() until after wait_for_full_sync(); new stream_blocks_after_sync helper + unit tests; collapses cfg-duplicated select arms.

Findings

Blocking (must fix before merge):

  • None.

Non-blocking (nits, follow-ups, suggestions):

  • crates/node/src/indexer/real.rs:288 — the doc comment on stream_blocks_after_sync is truncated mid-sentence: "...starting it early pins its cursor at genesis" (no terminating punctuation, no follow-up clause). Suggest closing it, e.g. "...pins its cursor at genesis, below the node's block tail." to match the inline comment at line 212–216.
  • crates/node/src/indexer/real.rs:298-307 — the test suite covers (a) sync-then-stream, (b) shutdown-before-sync, and (c) listen returns Err. It does not cover shutdown arriving while listen is running (cancelling the listen future). That's the dominant production path (SIGTERM on a healthy node), and only adding ~10 lines using a pending::<anyhow::Result<()>>() listen plus a tokio::spawn of shutdown.cancel(). Worth adding for symmetry.
  • crates/node/src/indexer/real.rs:212-227 — the comment block now bundles two distinct rationales (why we defer stream creation, and how shutdown cleanup works). It reads fine but could be split into two paragraphs with a blank // line between the "defer until synced" rationale and the "SIGTERM cleanup" rationale to make scanning easier. Stylistic only.
  • crates/node/src/indexer/real.rs:232wait_for_full_sync() was already implicitly awaited via monitor_contract_state(...).await at line 184 (it loops on wait_for_full_sync before returning the initial state). So in practice this second wait resolves immediately. Not a bug — the explicit wait is a useful local invariant and survives any future refactor that decouples those orderings — but worth noting in the PR description so reviewers don't wonder why both exist.

✅ Approved

🤖 Generated by Claude Code

Comment thread crates/node/src/indexer/real.rs
@gilcu3
gilcu3 force-pushed the 3623-mpc-indexer-wedges-at-genesis-on-a-freshly-state-synced-node branch from ed3fffe to cab024b Compare June 24, 2026 06:27
@gilcu3
gilcu3 force-pushed the 3623-mpc-indexer-wedges-at-genesis-on-a-freshly-state-synced-node branch from cab024b to 396c97b Compare June 24, 2026 06:37
kevindeforth
kevindeforth previously approved these changes Jun 24, 2026

@kevindeforth kevindeforth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!
Just some nits on excessive comments.

Comment thread crates/chain-gateway/src/chain_gateway.rs Outdated
Comment thread crates/chain-gateway/src/chain_gateway.rs Outdated
@kevindeforth
kevindeforth added this pull request to the merge queue Jun 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 24, 2026
@gilcu3
gilcu3 added this pull request to the merge queue Jun 24, 2026
Merged via the queue into main with commit bd3d75e Jun 24, 2026
15 checks passed
@gilcu3
gilcu3 deleted the 3623-mpc-indexer-wedges-at-genesis-on-a-freshly-state-synced-node branch June 24, 2026 09:27
nocktoshi pushed a commit to nocktoshi/mpc that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MPC indexer wedges at genesis on a freshly state-synced node

3 participants